package com.yizhubao.app.activitys.user;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.yizhubao.app.R;
import com.yizhubao.app.activitys.CancellationActivity;
import com.yizhubao.app.activitys.WebActivity;
import com.yizhubao.app.base.BaseActivityToolBar;
import com.yizhubao.app.base.BaseResultBean;
import com.yizhubao.app.customviews.BottomDialog;
import com.yizhubao.app.models.CancellationModel;
import com.yizhubao.app.utils.Utils;
import com.yizhubao.app.utils.net.BaseObserver;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import h.framework.pacy.P;
import h.framework.pacy.utils.AppUtil;
import h.framework.pacy.utils.LogUtil;
import h.framework.pacy.utils.ToastUtil;

/**
 * 创建人: PACY
 * 创建时间: 6/4/21 10:25 AM
 * 邮箱: pengwwe457621023@qq.com
 * 类描述: 设置
 */
public class SettingActivity extends BaseActivityToolBar {
    @BindView(R.id.version_tv)
    TextView version_tv;

    @BindView(R.id.zhuxiao_tv)
            TextView zhuxiao_tv;



    @Override
    protected int setContentLayout() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        setTitleOnLeftIcon(R.drawable.icon_back,"");
        version_tv.setText("版本号：V"+ AppUtil.getVersionName());
        if(Utils.isLogin()){
            zhuxiao_tv.setVisibility(View.VISIBLE);
        }else{
            zhuxiao_tv.setVisibility(View.GONE);
        }
    }

    @Override
    protected void initData() {

    }



    @OnClick(value = {R.id.xiaochengxu_tv,R.id.weibo_tv,R.id.yinsi_tv,R.id.xieyi_tv,R.id.toMarket_tv,R.id.zhuxiao_tv})
    public void click(View v){
       switch (v.getId()){
           case R.id.xiaochengxu_tv:
               BottomDialog.DialogBuilder(SettingActivity.this).title("微信小程序")
                       .message("①打开微信，搜索小程序“遗嘱宝”，即可通过小程序，使用遗嘱宝的服务；②如果APP上登录的微信号，和使用小程序的微信号，是同一个账号。那么所有的资料、信息，都将会是相同的。")
                        .completeText("知道了").show();
           break;
           case R.id.weibo_tv:
               BottomDialog.DialogBuilder(SettingActivity.this).title(
                       "微博官微")
                       .message("①打开微博，搜索“遗嘱宝”，您就可以找到我们的官微了；②请根据微博内容，一定要认准官微账号；③通过官微，您可以及时的关注到平台各类通知、公告、新闻。")
                       .completeText("知道了").show();
               break;

           case R.id.yinsi_tv:
               Bundle bundle=new Bundle();
               bundle.putString("title","隐私政策");
               bundle.putString("url","https://resource.weimingfang.com/pages/yinsizhengce.html");
               startActivity(SettingActivity.this, WebActivity.class,bundle);
               break;
           case R.id.xieyi_tv:
               Bundle bundle2=new Bundle();
               bundle2.putString("title","用户协议");
               bundle2.putString("url","https://resource.weimingfang.com/pages/yonghuxieyi.html");
               startActivity(SettingActivity.this, WebActivity.class,bundle2);
               break;

           case R.id.toMarket_tv:
               goToMarket();
               break;

               //注销账号
           case R.id.zhuxiao_tv:
               startActivity(SettingActivity.this, CancellationActivity.class);
               break;
       }
    }

    /**
     * 去应用市场评分
     */
    private void goToMarket() {
        if (!isMarketInstalled()) {
            ToastUtil.showShort("您的手机没有安装应用市场");
            return;
        }
        try {
            //Uri uri = Uri.parse("market://details?id="+getPackageName());
            Uri uri = Uri.parse("market://details?id=" + AppUtil.getPackageName(P.getContext()));
            LogUtil.i("market://details?id=" + AppUtil.getPackageName(P.getContext()));
            Intent intent = new Intent(Intent.ACTION_VIEW,uri);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }
        } catch (Exception e) {
            // 也可以调到某个网页应用市场
            ToastUtil.showShort("您的手机没有安装应用市场");
        }
    }

    /**
     * 本手机是否安装了应用市场
     * @return
     */
    public  boolean isMarketInstalled() {
        Intent intent = new Intent();
        intent.setData(Uri.parse("market://details?id=android.browser"));
        List list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return 0 != list.size();
    }

}